﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPremier.Areas.AdminCP.Models;

namespace VietPremier.Areas.AdminCP.Controllers
{
    public class AdminFooterController : Controller
    {
        //
        // GET: /AdminCP/AdminFooter/

        #region "Edit"
        public ActionResult Edit()
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                Footer model = new Footer();

                EntityFooter footer = db.EntityFooters.FirstOrDefault();
                model.ID = footer.Id;
                model.Body1 = footer.Body1;
                model.Body2 = footer.Body2;
                model.Body3 = footer.Body3;
                model.Body4 = footer.Body4;

                return View(model);
            }

        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(Footer model)
        {

            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                //check Id 
                EntityFooter footer = db.EntityFooters.Where(p => p.Id == model.ID).FirstOrDefault();
                if (footer != null)
                {
                    footer.Body1 = model.Body1;
                    footer.Body2 = model.Body2;
                    footer.Body3 = model.Body3;
                    footer.Body4 = model.Body4;

                    db.SubmitChanges();
                    TempData["EditSuccessfully"] = "You have successfully changed";
                    return RedirectToAction("Edit", "AdminFooter");
                }
                TempData["EditSuccessfully"] = "You have unsuccessfully changed";
                return RedirectToAction("Edit", "AdminFooter");
            }
        }

        #endregion //edit

    }
}
